Skip to content

Add SemanticCache vector index config#619

Open
omribz156 wants to merge 2 commits into
redis:mainfrom
omribz156:codex/semantic-cache-vector-index-config
Open

Add SemanticCache vector index config#619
omribz156 wants to merge 2 commits into
redis:mainfrom
omribz156:codex/semantic-cache-vector-index-config

Conversation

@omribz156

@omribz156 omribz156 commented May 25, 2026

Copy link
Copy Markdown

Summary

Addresses #602.

  • Add vector_index_config to SemanticCache so the cache vector field can be created with HNSW or other supported vector index options instead of always using FLAT.
  • Keep the default FLAT schema unchanged, and keep dims, datatype, and distance_metric derived from the vectorizer / semantic-cache COSINE behavior.
  • Document the HNSW configuration path in the LLM cache user guide.

Verification

  • .venv\Scripts\python.exe -m pytest --noconftest tests/unit/test_llmcache_schema.py
  • .venv\Scripts\python.exe -m black --check redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py
  • .venv\Scripts\python.exe -m compileall redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py
  • .venv\Scripts\python.exe -c "import json; json.load(open('docs/user_guide/03_llmcache.ipynb', encoding='utf-8')); print('notebook json ok')"
  • git diff --check

I also tried the normal pytest command first, but local execution without --noconftest is blocked on this Windows machine because the repo autouse fixture invokes Docker Compose and the Docker CLI is not available here.

This was implemented with Codex assistance, with the patch kept focused on the cache schema/config path and docs.


Note

Low Risk
Additive constructor option with unchanged default FLAT behavior; risk is mainly misconfigured index settings affecting search performance, not data or auth paths.

Overview
Adds optional vector_index_config on SemanticCache so the Redis vector field for prompt embeddings can use HNSW (or other supported algorithms) instead of always FLAT, while dims, datatype, and cosine distance still come from the vectorizer and are rejected if overridden in config.

SemanticCacheIndexSchema.from_params merges user config onto the default FLAT attrs and passes the result into index creation; the LLM cache user guide documents HNSW setup and notes that the algorithm is fixed after index creation (recreate with overwrite=True to change it).

Unit tests cover default FLAT, HNSW options, invalid algorithms, and blocked overrides of vectorizer-derived fields.

Reviewed by Cursor Bugbot for commit 40297d2. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Omri SirComp <omribz156@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable vector-index configuration path for SemanticCache, allowing the cache’s vector field to be created with HNSW (or other supported RedisVL vector algorithms) instead of being hardcoded to FLAT, and documents the new configuration in the LLM cache user guide.

Changes:

  • Extend SemanticCacheIndexSchema.from_params to accept vector_index_config and merge it into the vector field attrs while protecting vectorizer-derived attrs (dims, datatype, distance_metric).
  • Add vector_index_config plumbing to SemanticCache constructor so the schema/index can be created with a non-FLAT algorithm (e.g., HNSW).
  • Add unit tests for default FLAT behavior, HNSW config acceptance, and invalid config rejection; update the LLM cache notebook with a configuration example.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
redisvl/extensions/cache/llm/schema.py Adds vector_index_config support to the semantic cache index schema builder while preventing overrides of derived attrs.
redisvl/extensions/cache/llm/semantic.py Wires vector_index_config through SemanticCache initialization into schema/index creation.
tests/unit/test_llmcache_schema.py Adds unit coverage for FLAT default, HNSW config, and invalid algorithm/override behavior.
docs/user_guide/03_llmcache.ipynb Documents how to configure the semantic cache’s vector index algorithm (example: HNSW).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 52 to 56
filterable_fields: list[dict[str, Any]] | None = None,
vector_index_config: dict[str, Any] | None = None,
redis_client: Redis | None = None,
redis_url: str = "redis://localhost:6379",
connection_kwargs: dict[str, Any] = {},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 40297d2. I moved vector_index_config after overwrite in SemanticCache.init and kept the docstring in the same order, so existing positional redis_client/redis_url calls stay compatible. Verified with pytest --noconftest tests/unit/test_llmcache_schema.py, black --check, compileall, and git diff --check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants